/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package shooter;

import com.jme3.input.InputManager;
import com.jme3.input.KeyInput;
import com.jme3.input.controls.KeyTrigger;
import com.jme3.material.Material;
import com.jme3.math.ColorRGBA;
import com.jme3.math.Quaternion;
import com.jme3.math.Vector3f;
import com.jme3.renderer.RenderManager;
import com.jme3.renderer.ViewPort;
import com.jme3.scene.Geometry;
import com.jme3.scene.Node;
import com.jme3.scene.control.AbstractControl;
import com.jme3.scene.shape.Sphere;
import snails.*;

/**
 *
 * @author Samuel
 */
public class CannonDragControl extends AbstractControl
{
    Node parent;
    Cannon data;
    Geometry startGeom;
    Geometry endGeom;
    InputManager inputManager;
    
    
    
    public CannonDragControl(Node par, Cannon c)
    {
        parent = par;
        data = c;
        Sphere startPoint = new Sphere(5, 5, 1);
                startGeom = new Geometry("player", startPoint);
                 Material startMat = new Material(Main.cannonMods.assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
                 startMat.setColor("Color", ColorRGBA.Red);
                 startGeom.setMaterial(startMat);
                 startGeom.setLocalTranslation(c.getLocation());
                 parent.attachChild(startGeom);
        Sphere endPoint = new Sphere(5, 5, 1);
                 endGeom = new Geometry("player", endPoint);
                 Material endMat = new Material(Main.cannonMods.assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
                 endMat.setColor("Color", ColorRGBA.Green);
                 endGeom.setMaterial(endMat);
                 endGeom.setLocalTranslation(data.getLocation().add(data.getFacing().normalize().mult(5)));
                 parent.attachChild(endGeom);         
    }

    public void rotate(float tpf)
    {
        Quaternion q = new Quaternion();
        q.fromAngleAxis(tpf, Vector3f.UNIT_Y);
        Vector3f facing = q.mult(data.getFacing());
        //Vector3f newLoc = q.mult(facing.mult(5));
        endGeom.setLocalTranslation(data.getLocation().add(facing.mult(5)));
        data.setFacing(facing);
    }
    
    
    @Override
    protected void controlUpdate(float tpf)
    {
        
    }

    @Override
    protected void controlRender(RenderManager rm, ViewPort vp)
    {
        
    }
    
}
